//
//  AXFRankView.m
//  闪电超市
//
//  Created by 李典 on 16/11/8.
//  Copyright © 2016年 李典. All rights reserved.
//

#import "AXFRankView.h"

#import "AXFDetailsModel.h"

@interface AXFRankView ()
@property (nonatomic, weak) UIButton *oldBtn;
@property (nonatomic, weak) UIButton *allRankBtn;
@property (nonatomic, weak) UIButton *priceRankBtn;
@property (nonatomic, weak) UIButton *salesRankBtn;
@property (nonatomic, weak) UIButton *upBtn;
@property (nonatomic, weak) UIButton *downBtn;

@end

@implementation AXFRankView

- (instancetype)init
{
    if (self = [super init]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    UIButton *allRankBtn = [self creatBottonWithTitle:@"综合排序" tagNum:kAllRankBtn];
    UIButton *priceRankBtn = [self creatBottonWithTitle:@"按价格" tagNum:kPriceUpRankBtn];
    UIButton *salesRankBtn = [self creatBottonWithTitle:@"按销量" tagNum:kSalesRankBtn];
    NSArray<UIButton *> *arrayBtn = @[allRankBtn,priceRankBtn,salesRankBtn];
    
    [arrayBtn enumerateObjectsUsingBlock:^(UIButton *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self addSubview:obj];
    }];
    [arrayBtn mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    [arrayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
    }];
    // 箭头btn
    UIButton *upBtn = [[UIButton alloc]init];
    [upBtn setImage:[UIImage imageNamed:@"control-down"] forState:UIControlStateNormal];
    [upBtn setImage:[UIImage imageNamed:@"control-down-red"] forState:UIControlStateHighlighted];
    UIButton *downBtn = [[UIButton alloc]init];
    [downBtn setImage:[UIImage imageNamed:@"control-up"] forState:UIControlStateNormal];
    [downBtn setImage:[UIImage imageNamed:@"control-up-red"] forState:UIControlStateHighlighted];
    
    [priceRankBtn addSubview:upBtn];
    [priceRankBtn addSubview:downBtn];
    
    self.upBtn = upBtn;
    self.downBtn = downBtn;
    
    [upBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(priceRankBtn.mas_right).offset(-25);
        make.centerY.equalTo(priceRankBtn).offset(3);
    }];
    [downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(priceRankBtn.mas_right).offset(-25);
        make.centerY.equalTo(priceRankBtn).offset(-3);
    }];
    
    
    
    allRankBtn.selected = YES;
    self.oldBtn = allRankBtn;
}

- (UIButton *)creatBottonWithTitle:(NSString *)textBtn tagNum:(NSInteger)tag
{
    UIButton *btn = [UIButton cz_textButton:textBtn fontSize:13 normalColor:[UIColor blackColor] selectedColor:[UIColor cz_colorWithHex:0xff8a00]];
    btn.tag = tag;
    //    btn.titleLabel.attributedText = [NSAttributedString att]
    [btn addTarget:self action:@selector(clickBtnWithNum:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}
- (void)clickBtnWithNum:(UIButton *)btn
{
    self.oldBtn.selected = NO;
    btn.selected = YES;
    self.oldBtn = btn;
    
    self.upBtn.highlighted = NO;
    self.downBtn.highlighted = NO;
    if ([self.delegate respondsToSelector:@selector(againSequence:)]) {
        [self.delegate againSequence:btn];
    }
    if (btn.tag == kPriceUpRankBtn) {
        btn.tag = kPriceDownRankBtn;
        self.upBtn.highlighted = NO;
        self.downBtn.highlighted = YES;
    }
    else if(btn.tag == kPriceDownRankBtn){
        btn.tag = kPriceUpRankBtn;
        self.downBtn.highlighted = NO;
        self.upBtn.highlighted = YES;
    }
}

//  综合排序
- (void)allRankSequence
{
    //    [modelArray sortedArrayUsingComparator:^NSComparisonResult(HMNewsChannelModel *  _Nonnull obj1, HMNewsChannelModel *  _Nonnull obj2) {
    //        //      NSLog(@"%@ %@",obj1.tid,obj2.tid);
    //        //返回大小的顺序 默认是升序
    //        return [obj1.tid compare:obj2.tid];
    //    }];
    
}
//  按价格排序
//  按销量排序
@end
